package com.th.therp.controller;

import com.th.therp.pojo.dto.UserDto;
import com.th.therp.pojo.result.Result;
import com.th.therp.pojo.vo.LoginVo;
import com.th.therp.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @PostMapping("/register")
    public Result register(@RequestBody UserDto userDto){
        log.info("账号注册:{}", userDto);
        userService.register(userDto);
        return Result.success();
    }

    @ResponseBody
    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody UserDto userDto){
        log.info("账号登录:{}", userDto);
        LoginVo loginVo = userService.login(userDto);
        return Result.success(loginVo);
    }

    @ResponseBody
    @GetMapping("/sendCode")
    public Result sendCode() throws Exception {
        log.info("获取授权码");
        userService.sendCode();
        return Result.success();
    }
}